﻿@using winproject.Controllers;
@using winproject.Models;
@{
    ViewBag.Title = "Product - Details | Software-Kart.com";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";

    int resCode = 0;
    ProductDetails oItemEditDetail = null;
    if (ViewData != null && ViewData.Keys.Count() > 0 && ViewData.Keys.Contains("resCode"))
    {
        resCode = Convert.ToInt32(ViewData["resCode"]);
    }
    if (resCode == 250)
    {
        oItemEditDetail = (ProductDetails)ViewData["resData"];
    }
    
}

@Styles.Render("~/Content/Vendors")
<link type="text/css" rel="stylesheet" href="~/Content/css/jquery-te-1.4.0.css">
<script type="text/javascript" src="~/Scripts/jquery-te-1.4.0.js" charset="utf-8"></script>
@Html.Partial("_LeftMenu")


<!-- content -->
<div class="col-md-10">
    
    <div class="row">
        <div class="panel panel-default bootstrap-admin-no-table-panel">
            <div class="panel-heading">
                <div class="text-muted bootstrap-admin-box-title">Product > Details</div>
            </div>
            <div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
                <form id="frmProdDetail" action="~/Products/AddProductDetails"  method="post" enctype="multipart/form-data" >
                    @{
                        if (oItemEditDetail != null && (oItemEditDetail.nPid) > 0)
                        {
                            <input type="hidden" id="txtUniqueId" name="txtUniqueId" value="@oItemEditDetail.nPid" />
                        }
                        else
                        {
                            <input type="hidden" id="txtUniqueId" name="txtUniqueId" value="0" />   
                        }
                     }
                <table width="100%"  cellpadding="5" class="table-striped">
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Select Category
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                List<CategoryDetails> lsCatList = (List<CategoryDetails>)ViewData["Categories"];
                                
                                <select id="drpCategory" name="drpCategory" onchange="return getBasedSubCategory(this.value,'drpSubCategory',containerTypes.options);">
                                    <option value="0">--Select Category--</option>
                                    @{
                                        if (lsCatList != null && lsCatList.Count > 0)
                                        {
                                            string selectedStr = "";
                                            foreach (var lsCat in lsCatList)
                                            {
                                                if (oItemEditDetail != null && oItemEditDetail.nCid > 0)
                                                {
                                                    if (oItemEditDetail.nCid == lsCat.nItemId)
                                                    {
                                                        selectedStr = "selected=\"true\"";
                                                    }
                                                    else{
                                                        selectedStr = "";
                                                    }
                                                }
                                                //selectedStr=(oItemEditDetail.nParentId == lsCat.nItemId ? "selected=\"true\"" : "");
                                                <option value="@lsCat.nItemId" @selectedStr>
                                                    @lsCat.sItemName
                                                </option>
                                            }
                                        }
                                    }
                                </select>
                                
                                
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Select Sub Category @*@oItemEditDetail.nSCid*@
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            <select id="drpSubCategory" name="drpSubCategory">
                                <option value="0">--Select Sub Category--</option>
                                @{
                                    if (oItemEditDetail != null && (oItemEditDetail.nSCid) > 0)
                                    {
                                        HelperController oHelper = new HelperController();
                                        ReturnResult oResult = null;
                                        SubCategoryDetails oSubCatSearch= new SubCategoryDetails();
                                        oSubCatSearch.nParentId=oItemEditDetail.nCid;
                                        List<SubCategoryDetails> lsSubCat = oHelper.GetSubCategoryDetails(out oResult, oSubCatSearch);
                                        if (oResult.errCode == (int)cEnums.eErrorCodes.Success)
                                        {
                                            if (lsSubCat != null && lsSubCat.Count > 0)
                                            {
                                                string selectedStr = "";
                                                foreach (var lsSCat in lsSubCat)
                                                {
                                                    if (oItemEditDetail.nSCid == lsSCat.nItemId)
                                                    {
                                                        selectedStr = "selected=\"true\"";
                                                    }
                                                    else
                                                    {
                                                        selectedStr = "";
                                                    }
                                                     <option value="@lsSCat.nItemId" @selectedStr>
                                                        @lsSCat.sItemName
                                                    </option>
                                                }
                                            }
                                        }
                                        lsSubCat = null;
                                        oResult = null;
                                    }
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Product Name
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sTitle))
                                {
                                    <input type="text" id="txtProdName" name="txtProdName" value="@oItemEditDetail.sTitle.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtProdName" name="txtProdName" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Product Slug
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sSlug))
                                {
                                    <input type="text" id="txtProductSlug" name="txtProductSlug" value="@oItemEditDetail.sSlug.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtProductSlug" name="txtProductSlug" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top" >
                            Description
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td style="vertical-align:top">
                            <textarea id="txtProductDesc" name="txtProductDesc" class="jqte-test">
                                 @{
                                     if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sDesc))
                                     {
                                        @WebUtility.HtmlDecode(oItemEditDetail.sDesc)
                                     }
                                }
                            </textarea>

                        </td>
                    </tr>
                    


                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Home Link
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sHomelnk))
                                {
                                    <input type="text" id="txtProdHomeLink" name="txtProdHomeLink" value="@oItemEditDetail.sHomelnk.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtProdHomeLink" name="txtProdHomeLink" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Download Link
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sDownloadlnk))
                                {
                                    <input type="text" id="txtProdDownloadLink" name="txtProdDownloadLink" value="@oItemEditDetail.sDownloadlnk.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtProdDownloadLink" name="txtProdDownloadLink" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Buy-Now Link
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sBuyNowlnk))
                                {
                                    <input type="text" id="txtProdBuyNowLink" name="txtProdBuyNowLink" value="@oItemEditDetail.sBuyNowlnk.Trim()"/>
                                }
                                else
                                {
                                    <input type="text" id="txtProdBuyNowLink" name="txtProdBuyNowLink" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Company Name
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && !string.IsNullOrEmpty(oItemEditDetail.sCompanyName))
                                {
                                    <input type="text" id="txtProdCompany" name="txtProdCompany" value="@oItemEditDetail.sCompanyName.Trim()" />
                                }
                                else
                                {
                                    <input type="text" id="txtProdCompany" name="txtProdCompany" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Select Currency
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            <select id="drpCurrency" name="drpCurrency">
                                <option value="0">--Select Currency--</option>
                                 @{
                                    if (oItemEditDetail != null && (oItemEditDetail.nCurrency) > 0)
                                    {
                                        HelperController oHelper = new HelperController();
                                        ReturnResult oResult = null;
                                        List<CurrencyDetails> lsCurList = oHelper.GetCurrencyDetails(out oResult);
                                        if (oResult.errCode == (int)cEnums.eErrorCodes.Success)
                                        {
                                            if (lsCurList != null && lsCurList.Count > 0)
                                            {
                                                string selectedStr = "";
                                                foreach (var lsCur in lsCurList)
                                                {
                                                    if (oItemEditDetail.nCurrency == lsCur.nID)
                                                    {
                                                        selectedStr = "selected=\"true\"";
                                                    }
                                                    else{
                                                        selectedStr = "";
                                                    }
                                                     <option value="@lsCur.nID" @selectedStr>
                                                        @lsCur.sCurISO | @lsCur.sCurName
                                                    </option>
                                                }
                                            }
                                        }
                                        lsCurList = null;
                                        oResult = null;
                                    }
                                }
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Base Price
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && (oItemEditDetail.dBasePrice) > 0)
                                {
                                    <input type="text" id="txtProdBasePrice" name="txtProdBasePrice" value="@oItemEditDetail.dBasePrice"/>
                                }
                                else
                                {
                                    <input type="text" id="txtProdBasePrice" name="txtProdBasePrice" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Enter Discount
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && (oItemEditDetail.nDiscountOffered) > 0)
                                {
                                    <input type="text" id="txtProdDiscount" name="txtProdDiscount" value="@oItemEditDetail.nDiscountOffered"/>
                                }
                                else
                                {
                                    <input type="text" id="txtProdDiscount" name="txtProdDiscount" />
                                }
                            }
                        </td>
                    </tr>
                    <tr>
                        <td style="width:200px;vertical-align:top">
                            Net Price
                        </td>
                        <td style="width:20px;vertical-align:top">:</td>
                        <td>
                            @{
                                if (oItemEditDetail != null && (oItemEditDetail.dNetPrice) > 0)
                                {
                                    <input type="text" id="txtProdNetPrice" name="txtProdNetPrice" value="@oItemEditDetail.dNetPrice"/>
                                }
                                else
                                {
                                    <input type="text" id="txtProdNetPrice" name="txtProdNetPrice" />
                                }
                            }
                        </td>
                    </tr>
                    

                    <tr>
                        <td colspan="2">
                            &nbsp;
                        </td>
                        <td class="text-left">
                            @{
                                if (oItemEditDetail != null && (oItemEditDetail.nPid) > 0)
                                {
                                    <button type="submit" id="cmdSave" name="cmdSave" value="Save">Save</button>
                                }
                                else
                                {
                                    <button type="submit" id="cmdSave" name="cmdSave" value="Add">Add</button>
                                }
                            }
                            &nbsp; &nbsp;
                            <button type="button" id="cmdCancel" name="cmdSave" value="Cancel" onclick="window.location.href='@HttpContext.Current.Request.ApplicationPath/Admin/SubCategory'">Cancel</button>
                        </td>
                    </tr>
                </table>
                </form>
            </div>
        </div>
    </div>
    
</div>


<script>
    //Declarations
    var itemGridListGlobal = [];

    
    
    function editItem(itemid) {
        if (!isNaN(itemid) && parseInt(itemid) > 0) {
            $("#txtUniqueId").val(itemid);
            $("#frmProdDetail").attr("action", approotpath + "Products/Detail");
            $("#frmProdDetail").submit();
        }
    }
    
    function deleteItem(itemid, targetitem) {
        if (confirm("Are you sure want to delete?")) {
            switch (targetitem) {
                case 'prod-item':
                    deleteProdItem(itemid);
                    break;
            }
        }
    }
    

    function deleteProdItem(itemid) {
        if (!isNaN(itemid) && parseInt(itemid) > 0) {
            var oItemdetail = new ProductDetails();
            oItemdetail.nPid = itemid;
            $(document).ready(function () {
                $.ajax(approotpath + "Products/DeleteProduct", {
                    data: oItemdetail,
                    type: "POST",
                    dataType: 'json',
                    success: function (data) {
                        var dataJson = data;//$.parseJSON(data);
                        if (parseInt(dataJson.errCode) == 250) {
                            if (document.getElementById("info-" + itemid + "-item")) {
                                $("#info-" + itemid + "-item").remove();
                                if ($("#list_info").find("tr").length <= 0) {
                                    $("#list_info").append(noRecordExist(5, "No More Records Exists"));
                                }
                                alert("Item removed");
                            }
                        }
                    }
                });
            });
        }
    }

    @{
        int nCurId=0;
        if(oItemEditDetail != null && oItemEditDetail.nCurrency > 0){
         nCurId=oItemEditDetail.nCurrency ;   
        }
    }
    //load dynamic data on load time
    $(document).ready(function () {        
        getBasedCurrency('drpCurrency', containerTypes.options,@nCurId);
    });


    //getVirusDetail():: fetches virus details
    
    

    function noRecordExist(cellpadding, strMsg) {
        return "<tr><td class='text-center' colspan='" + cellpadding + "' style='padding:20px;color:red'>" + strMsg + "</td></tr>";
    }


    $('.jqte-test').jqte();

    // settings of status
    var jqteStatus = true;
    $(".status").click(function () {
        jqteStatus = jqteStatus ? false : true;
        $('.jqte-test').jqte({ "status": jqteStatus })
    });


</script>

